#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

void Print(int* arr, int n)
{
	for (int i = 0;i < n;i++)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");
}

void InsertSort(int* arr, int n)
{
	for (int i = 0;i < n - 1;i++)
	{
		int end = i;
		int tmp = arr[end + 1];
		while (end >= 0)
		{
			if (tmp < arr[end])
			{
				arr[end + 1] = arr[end];
				end--;
			}
			else
			{
				break;
			}
		}
		arr[end + 1] = tmp;
	}
}

int main()
{
	int arr[] = { 5,8,7,9,3,1,4,6,0 };
	int n = sizeof(arr) / sizeof(arr[0]);
	printf("排序前：");
	Print(arr, n);
	InsertSort(arr, n);
	printf("排序后: ");
	Print(arr, n);
	return 0;
}